import { _decorator, Component, Node, Vec2 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('camera')
export class camera extends Component {
    @property(Node)
    target: Node;
    pos: Vec2;
    start() {
        const p1 = this.target.position;
        const p2 = this.node.position;
        this.pos = new Vec2(p1.x, p2.y - p1.y + 100);
    }

    lateUpdate(deltaTime: number) {
        let startx = this.target.position.x
        if (startx < -240) {
            startx = -240
        } else if (startx > 2560) {
            startx = 2560
        }
        this.node.setPosition(startx, this.pos.y + this.target.position.y);
    }

}


